package com.zhang.bingmei_incomeexpenditure.service.factory;

import cn.hutool.core.bean.BeanUtil;
import com.zhang.bingmei_incomeexpenditure.entity.ie.IncomeExpenditure;
import com.zhang.bingmei_incomeexpenditure.entity.ie.selectNew.SelectDoubleVO;
import com.zhang.bingmei_incomeexpenditure.entity.ie.updateNew.UpdateDoubleVO;
import com.zhang.bingmei_incomeexpenditure.entity.Utils.IECommUtil;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 数据转换工厂：统一对象转换逻辑
 */
public class DataConvertFactory {
    /**
     * Entity -> SelectDoubleVO
     */
    public static List<SelectDoubleVO> convertToSelectDoubleVO(List<IncomeExpenditure> entities) {
        return entities.stream()
                .map(entity -> {
                    SelectDoubleVO vo = BeanUtil.copyProperties(entity, SelectDoubleVO.class);
                    // 金额字段转换：Long → Double
                    vo.setCityAllocated(IECommUtil.longToDouble(entity.getCityAllocated()));
                    vo.setDistrictAllocated(IECommUtil.longToDouble(entity.getDistrictAllocated()));
                    vo.setOtherFunds(IECommUtil.longToDouble(entity.getOtherFunds()));
                    vo.setTotalFunds(IECommUtil.longToDouble(entity.getTotalFunds()));
                    // 其他金额字段...
                    return vo;
                })
                .collect(Collectors.toList());
    }

    /**
     * Entity -> UpdateDoubleVO
     */
    public static List<UpdateDoubleVO> convertToUpdateDoubleVO(List<IncomeExpenditure> entities) {
        return entities.stream()
                .map(entity -> {
                    UpdateDoubleVO vo = BeanUtil.copyProperties(entity, UpdateDoubleVO.class);
                    // 金额字段转换
                    vo.setCityAllocated(IECommUtil.longToDouble(entity.getCityAllocated()));
                    // 其他金额字段...
                    return vo;
                })
                .collect(Collectors.toList());
    }
}